import java.util.List;
import java.util.ArrayList;

public class Solution {
    public static void main(String[] args) {
    	Solution s = new Solution();
	String[] words = {""};
	List<String> ans = s.fullJustify(words, 2);
	System.out.println(ans);
    }

    public List<String> fullJustify(String[] words, int L) {
        List<String> res = new ArrayList<String>();
        if (words.length == 0)
            return res;
        if (L <= 0) {
            for (String word : words)
                res.add(word);
            return res;
        }
        
        int i = 0;
        while(true) {
            if (i >= words.length)
                break;
            
            StringBuffer sb = new StringBuffer();
        
            int wc = 0;
            int len = 0;
            int j = i;
            for(; j < words.length; j++) {
                if (len + words[j].length() + wc <= L) {
                    len += words[j].length();
                    wc++;
                    j++;
                } else {
                    break;
                }
            }
	    System.out.println(words.length + " " + j);
            
            if (j < words.length) {
                assert (wc >= 1);
                if (wc == 1)
                    sb.append(words[i]);
                else {
                    int nspaces = (L - len) / (wc-1);
                    int remains = (L - len) % (wc-1);
                    for (int k = i; k < j; ++k) {
                        sb.append(words[k]);
                        for (int s = nspaces; s > 0; s--)
                            sb.append(' ');
                        if (remains > 0) {
                            sb.append(' ');
                            remains--;
                        }
                    }
                    sb.append(words[j]);
                }
            } else {
		    System.out.println(j);
                for (int k = i; k < j; ++k) {
                    sb.append(words[k]);
                }
            }
            
            res.add(sb.toString());
            i = j;
        }
        
        return res;
    }
}
